import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

Dio dio = new Dio();

class MovieDetail extends StatefulWidget {
  MovieDetail({Key key, @required this.id, @required this.title})
      : super(key: key);

  final String id;

  final String title;

  @override
  _MovieDetailState createState() {
    return _MovieDetailState();
  }
}

class _MovieDetailState extends State<MovieDetail> {
  var title = '';
  var id = '';

  @override
  void initState() {
    super.initState();
    getMovieDetail();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '${widget.title}----${widget.id}',
          style: TextStyle(color: Colors.white, fontSize: 18.0),
        ),
        centerTitle: true,
      ),
      body: Container(
        child: Text('$title'),
      ),
    );
  }

  getMovieDetail() async {
    print('${widget.id}');
    var url =
        'http://www.liulongbin.top:3005/api/v2/movie/subject/${widget.id}';
    var response = await dio.get(url);
    var result = response.data;
    print(result);
    setState(() {
      title = result['title'];
      id = result['id'];
    });
  }
}
